Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(python): fix error message when creating DataFrame from 0-dimensional NumPy array #13729

Merged
merged 3 commits into from
Jan 15, 2024

Conversation

Wainberg
Copy link
Contributor

Before:

>>> pl.DataFrame(np.array(1))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "polars/py-polars/polars/dataframe/frame.py", line 394, in __init__
    self._df = numpy_to_pydf(
               ^^^^^^^^^^^^^^
  File "polars/py-polars/polars/utils/_construction.py", line 1451, in numpy_to_pydf
    raise ValueError(msg)
ValueError: cannot create DataFrame from array with more than two dimensions; shape = ()

After:

>>> pl.DataFrame(np.array(1))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "polars/py-polars/polars/dataframe/frame.py", line 394, in __init__
    self._df = numpy_to_pydf(
               ^^^^^^^^^^^^^^
  File "polars/py-polars/polars/utils/_construction.py", line 1454, in numpy_to_pydf
    raise ValueError(msg)
ValueError: cannot create DataFrame from zero-dimensional array

@ritchie46
Copy link
Member

Thanks, can you add a test?

@Wainberg
Copy link
Contributor Author

Thanks, can you add a test?

Done!

@ritchie46 ritchie46 merged commit 9286a85 into pola-rs:main Jan 15, 2024
11 checks passed
@Wainberg Wainberg deleted the numpy-0d-error branch January 15, 2024 23:17
r-brink pushed a commit to r-brink/polars that referenced this pull request Jan 24, 2024
…onal NumPy array (pola-rs#13729)

Co-authored-by: Wainberg <m.wainberg@utoronto.ca>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix python Related to Python Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants